{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-page">
	<div class="layui-card border-x border-t" style="margin-bottom:0; box-shadow:0 0 0 0 rgb(5 32 96 / 0%)">
		<div class="body-table layui-tab layui-tab-brief" lay-filter="tab">
			<ul class="layui-tab-title">
				<li class="layui-this">全部</li>
				<li>我申请的</li>
				<li>待我审批</li>
				<li>我已审批</li>
				<li>抄送我的</li>
			</ul>
		</div>
	</div>
	<form class="layui-form gg-form-bar border-x tab-0" id="barsearchform">
		<div class="layui-input-inline search-item" style="width:150px;">
			<select name="check_status">
				<option value="">选择审批状态</option>
				{volist name=":get_check_status()" id="vo"}
				<option value="{$key}">{$vo}</option>
				{/volist}
			</select>
		</div>
		<div class="layui-input-inline" style="width:175px;">
			<input type="text" class="layui-input" id="move_time" placeholder="选择调动日期" readonly name="move_time">
		</div>
		<div class="layui-input-inline" style="width:150px">
			<input type="hidden" name="tab" value="0"/>
			<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="table-search"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
			<button type="reset" class="layui-btn layui-btn-reset" lay-filter="table-reset">清空</button>
		</div>
	</form>
	<table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
	<button class="layui-btn layui-btn-sm" lay-event="add">+ 添加人事调动申请</button>
  </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','tablePlus','laydatePlus','oaPicker'];
	function gouguInit() {
		var table = layui.tablePlus, tool = layui.tool,form = layui.form,element = layui.element,laydatePlus = layui.laydatePlus;
		//日期范围
		var move_time = new laydatePlus({'target':'move_time'});
		//tab切换
		element.on('tab(tab)', function(data){
			$('[name="tab"]').val(data.index);
			$("#barsearchform")[0].reset();
			layui.pageTable.reload({where:{tab:data.index},page:{curr:1}});
			return false;
		});
		layui.pageTable = table.render({
			elem: '#test'
			, toolbar: '#toolbarDemo'
			,defaultToolbar: false
			, url: "/user/personal/change"
			, page: true //开启分页
			, limit: 20
			, height: 'full-154'
			, cols: [[
				{ field: 'id', width: 80, title: '序号', align: 'center' }
				,{field:'check_status',title: '审批状态',width:110, align:'center',templet: function(d){
						var html = '<span class="check-status-color-'+d.check_status+'">『'+d.check_status_str+'』</span>';
						return html;
					}
				 }
				, { field: 'name', width: 80, title: '员工姓名', align: 'center'}
				, { field: 'from_department', width: 150, title: '调出部门','style':'color:#FF5722'}
				, { field: 'to_department', width: 150, title: '调入部门','style':'color:#1e9fff'}
				, { field: 'status', width: 80,title: '执行状态', align: 'center',
					templet: function (d) {
						if(d.status==1){
							return '<span class="green">未执行</span>';
						}
						else{
							return '<span class="red">已执行</span>';
						}
					}
				}
				, { field: 'move_time', title: '调动日期',width: 100, align: 'center'}
				, { field: 'remark', title: '调动原因'}
				, {field: 'admin_name',title: '申请人',align: 'center',width: 80}
				, {field: 'create_time',title: '申请时间',align: 'center',width: 150}
				, {field: 'check_user',title: '当前审核人'}
				, {
						field: 'right',
						fixed: 'right',
						title: '操作',
						width: 130,
						align: 'center',
						templet:function(d){
							var html='<div class="layui-btn-group">';
							var btn1='<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">详情</span>';
							var btn2='<span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>';
							var btn3='<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>';
							let	btn4='<button class="layui-btn layui-bg-orange layui-btn-xs" lay-event="set">执行</button>';
							html+=btn1;
							if((d.check_status==0 || d.check_status==4) && d.admin_id==login_admin){
								html+=btn2+btn3;
							}
							if(d.check_status==2 && d.status==1){
								html+=btn4;
							}
							html+='</div>';
							return html;
						}
					}
			]]
		});
		
		//监听行工具事件
		table.on('tool(test)', function(obj){
			var data = obj.data;
			if(obj.event === 'edit'){
				tool.side('/user/personal/change_add?id='+data.id);
				return;
			}
			if(obj.event === 'view'){
				tool.side('/user/personal/change_view?id='+data.id);
				return;
			}
			if (obj.event === 'set') {
				layer.confirm('确定要执行部门调动吗?', { icon: 3, title: '提示' }, function (index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							layui.pageTable.reload();
						}
					}
					tool.delete("/user/api/change_check", { id: data.id }, callback);
					layer.close(index);
				});
			}
			if (obj.event === 'del') {
				layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							layui.pageTable.reload();
						}
					}
					tool.delete("/user/personal/change_delete", { id: data.id }, callback);
					layer.close(index);
				});
			}
		});
		
		//表头工具栏事件
		table.on('toolbar(test)', function(obj){
			if (obj.event === 'add') {
				tool.side("/user/personal/change_add");
				return;
			}
		});

		//监听搜索提交
		form.on('submit(webform)', function(data){
			if(data.field.keywords) {
				layui.pageTable.reload({where:{keywords:data.field.keywords},page:{curr:1}});			  
			}
			else{
				location.reload();
			}
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->